<?php

class Descritor_Model extends CI_Model{

    var $id = '';
    var $nome = '';

    function __construct()
    {
        parent::__construct();
    }


    function salvar(){
        $this->id = $this->input->post('id');
        $this->nome = $this->input->post('nome');

        if($this->id == ''){
            $this->db->insert('descritores', $this);
        } else{
            $this->db->update('descritores', $this, array('id' => $this->id));
        }

    }

    function delete(){
        $this->db->delete('descritores', array('id' => $this->input->post('id'))); 
    }

    function listar(){
        $params = array();
        if($this->input->get('nome') != ''){
            $this->db->like('nome', $this->input->get('nome'));
        }
        
        $this->db->where($params);
        $query = $this->db->get( 'descritores');
        return $query->result_array();    
    }

    function consultar_por_id(){
        $this->db->where('id', $this->input->get('id'));
        $query = $this->db->get('descritores');
        $array = $query->result_array();
        return $array[0]; 
    }

}


?>